package com.spark.lola.controller;


import com.spark.lola.mapper.OrderInfoMapper;
import com.spark.lola.service.IOrderInfoService;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;
import com.spark.lola.support.mybatis.controller.BaseController;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.spark.lola.entity.warehouse.OrderInfo;
import com.spark.lola.support.common.constant.CommonConstant;
import com.spark.lola.support.common.entity.ShiroUser;
import com.spark.lola.support.common.util.DataBeanUtils;
import com.spark.lola.support.common.util.ResponseBean;
import com.spark.lola.support.mybatis.entity.PageParam;
import com.spark.lola.support.mybatis.entity.QueryParam;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.transaction.annotation.Transactional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 采购入库单 前端控制器
 * </p>
 *
 * @author dengyejun
 * @since 2020-06-15
 */
@RestController
@RequestMapping("/api/order-info")
public class OrderInfoController extends BaseController {
    private static final Logger logger = LoggerFactory.getLogger(OrderInfoController.class);
    @Autowired
    private OrderInfoMapper currentMapper;
    @Autowired
    private IOrderInfoService currentService;

    @RequiresPermissions(value = "m7310")
    @RequestMapping(value = "/findBy", consumes = "application/json")
    public ResponseBean findBy(@RequestBody QueryParam<OrderInfo> queryBean,
                               @SessionAttribute ShiroUser shiroUser) {
        PageParam<OrderInfo> pageParam = queryBean.toPageParam();
        IPage<OrderInfo> page = currentMapper.selectPage(pageParam.getPage(), pageParam.getEntityWrapper());
        return ResponseBean.success(page);
    }

    @RequiresPermissions(value = "m7310")
    @RequestMapping(value = "/findInfo/{id}", method = RequestMethod.GET)
    public ResponseBean findInfo(@PathVariable Long id,
                                 @SessionAttribute ShiroUser shiroUser) {
        OrderInfo model;
        if (id == 0) {
            model = new OrderInfo();
        } else {
            model = currentService.getById(id);
        }
        return ResponseBean.success(model);
    }



}
